package controllayer;

import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The test class LoanCtrlTest.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class LoanCtrlTest
{
    private controllayer.PersonCtrl personCt1;
    private controllayer.DVDCtrl dVDCtrl1;
    private controllayer.LoanCtrl loanCtrl1;
    private static int counter = 1;

    /**
     * Default constructor for test class LoanCtrlTest
     */
    public LoanCtrlTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {

    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
        personCt1 = null;
        dVDCtrl1 = null;
        loanCtrl1 = null;
    }

    @Test
    public void createLoan()
    {
        controllayer.PersonCtrl personCt1 = new controllayer.PersonCtrl();
        controllayer.DVDCtrl dVDCtrl1 = new controllayer.DVDCtrl();
        controllayer.LoanCtrl loanCtrl1 = new controllayer.LoanCtrl();
        dVDCtrl1.createDVD("Die Hard", "123456789", "11/11/1111");
        dVDCtrl1.addCopy("Die Hard", "1", "11/11/1111", "123");
        personCt1.createPerson("Finn", "", "", "", "112");
        assertEquals("confirmed", loanCtrl1.createLoan("11/11/1111", "14", "112", "Die Hard"));
        loanCtrl1.deleteLoan("112", counter);
        dVDCtrl1.deleteDVD("Die Hard");
        personCt1.deletePerson("112");
        counter++;
    }

    @Test
    public void createSubLoan()
    {
        controllayer.PersonCtrl personCt1 = new controllayer.PersonCtrl();
        controllayer.DVDCtrl dVDCtrl1 = new controllayer.DVDCtrl();
        controllayer.LoanCtrl loanCtrl1 = new controllayer.LoanCtrl();
        personCt1.createPerson("Finn", "", "", "", "112");
        assertEquals("DVD created", dVDCtrl1.createDVD("Die Hard", "", "11/11/1111"));
        assertEquals("Copy created", dVDCtrl1.addCopy("Die Hard", "1", "11/11/1111", ""));
        assertEquals("Copy created", dVDCtrl1.addCopy("Die Hard", "2", "11/11/1111", ""));
        assertEquals("confirmed", loanCtrl1.createLoan("11/11/1111", "14", "112", "Die Hard"));
        assertEquals("Copy added to loan!", loanCtrl1.addSubLoan("112", "Die Hard", counter, "11/11/1111", "14"));
        loanCtrl1.deleteLoan("112", counter);
        dVDCtrl1.deleteDVD("Die Hard");
        personCt1.deletePerson("112");
        counter++;
    }

    @Test
    public void returnSubLoan()
    {
         controllayer.PersonCtrl personCt1 = new controllayer.PersonCtrl();
        controllayer.DVDCtrl dVDCtrl1 = new controllayer.DVDCtrl();
        controllayer.LoanCtrl loanCtrl1 = new controllayer.LoanCtrl();
        dVDCtrl1.createDVD("Die Hard", "", "11/11/1111");
        personCt1.createPerson("Finn", "", "", "", "112");
        dVDCtrl1.addCopy("Die Hard", "1", "", "");
        loanCtrl1.createLoan("11/11/1111", "", "112", "Die Hard");
        assertEquals(true, loanCtrl1.returnSubLoan("112", "Die Hard", "1", counter));
        loanCtrl1.deleteLoan("112", counter);
        dVDCtrl1.deleteDVD("Die Hard");
        personCt1.deletePerson("112");
        counter++;
    }
}




